package koyi.android.learningproject;

import koyi.android.learningproject.adapters.ExpandableListAdapter;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ExpandableListView.OnGroupExpandListener;

public class ExpandableListViewActivity extends FragmentActivity {
	
	private ExpandableListView expanList = null;
	private int previousGroup = -1;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.expandable_list_view);
		
		expanList = (ExpandableListView) findViewById(R.id.expandableListView);
		BaseExpandableListAdapter adapter = new ExpandableListAdapter();
		expanList.setAdapter(adapter);
		
		expanList.setOnGroupClickListener(new OnGroupClickListener() {
			
	        @Override
	        public boolean onGroupClick(ExpandableListView arg0, View arg1,
	            int groupPosition, long arg3) {
	        	
	            return false;
	        }
        });
	 
		expanList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
		    @Override
		    public boolean onChildClick(ExpandableListView parent,
		            View v, int groupPosition, int childPosition,
		            long id) {
	
	           
		 
		        return false;
		    }
	    });
		
		expanList.setOnGroupExpandListener(new OnGroupExpandListener() {
			
			@Override
			public void onGroupExpand(int groupPosition) {
				
				if(previousGroup != groupPosition) {
					expanList.collapseGroup(previousGroup);
					previousGroup = groupPosition;
				}
				
				
			}
		});
	}
}
